Imports System.Data.Common
Partial Class Presentation_Management_PersonsProgress
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim Sql As String
        Dim Records As DbDataReader
        Dim CountSql As String
        Dim Params(0) As GenParameter
        Dim SortOrder As String

        Page.Title = "Person's Progress"


        If Not Page.IsPostBack Then

            If Not User.IsInRole("Top Management") Then

                Sql = "Select ExecutiveID, ExecutiveName from ExecutiveMaster" & _
                    " WHERE Location = ?Location AND Active = 1 AND DepartmentID = 2" & _
                    " ORDER BY ExecutiveName"
            Else
                Sql = "Select ExecutiveID, ExecutiveName from ExecutiveMaster" & _
                " WHERE Active = 1 AND DepartmentID = 2" & _
                " ORDER BY ExecutiveName"



            End If

            
            Params(0) = New GenParameter("?Location", Request.Cookies("Profile").Item("Location"), Data.DbType.String)

            Records = GenHelper.ExecuteReader(Sql, Params, ConfigurationManager.ConnectionStrings.Item("MySqlConnString").ToString())

            dlPerson.DataValueField = "ExecutiveID"
            dlPerson.DataTextField = "ExecutiveName"
            dlPerson.DataSource = Records
            dlPerson.DataBind()

        End If

        Select Case SelectSort.SelectedValue

            Case "NameSort"
                SortOrder = " ORDER BY ClientName"
            Case "DateSort"
                SortOrder = " ORDER BY MeetingDate desc"
            Case Else
                SortOrder = " ORDER BY ClientName"
        End Select

        Sql = "SELECT ProjectMaster.ProjectName, DATE_FORMAT(WorkflowMaster.MeetingDate,'%d/%m/%y') AS 'Meeting Date', " & _
            "ClientMaster.ClientName, ActionMaster.ActionDescription, WorkflowMaster.Details, WorkflowMaster.NextAction, " & _
            "DATE_FORMAT(WorkflowMaster.DateofNextAction,'%d/%m/%y') AS 'Date of Next Action', StatusMaster.StatusDescription " & _
            "FROM ActionMaster INNER JOIN (ProjectMaster INNER JOIN (ExecutiveMaster INNER JOIN " & _
            "(ClientMaster INNER JOIN (StatusMaster INNER JOIN WorkflowMaster ON StatusMaster.StatusID = WorkflowMaster.StatusID) " & _
            "ON ClientMaster.ClientID = WorkflowMaster.ClientID) ON ExecutiveMaster.ExecutiveID = WorkflowMaster.ExecutiveID) " & _
            "ON ProjectMaster.ProjectID = WorkflowMaster.ProjectID) ON ActionMaster.ActionID = WorkflowMaster.ActionID " & _
            "WHERE ExecutiveMaster.ExecutiveID = ?ExecutiveID " & " " & SortOrder

        CountSql = "SELECT COUNT(*) " & _
            "FROM ActionMaster INNER JOIN (ProjectMaster INNER JOIN (ExecutiveMaster INNER JOIN " & _
            "(ClientMaster INNER JOIN (StatusMaster INNER JOIN WorkflowMaster ON StatusMaster.StatusID = WorkflowMaster.StatusID) " & _
            "ON ClientMaster.ClientID = WorkflowMaster.ClientID) ON ExecutiveMaster.ExecutiveID = WorkflowMaster.ExecutiveID) " & _
            "ON ProjectMaster.ProjectID = WorkflowMaster.ProjectID) ON ActionMaster.ActionID = WorkflowMaster.ActionID " & _
            "WHERE ExecutiveMaster.ExecutiveID = ?ExecutiveID " & " " & SortOrder

        Params(0) = New GenParameter("?ExecutiveID", dlPerson.SelectedValue, Data.DbType.UInt32)

        cstmPersonsProgress.Sql = Sql
        cstmPersonsProgress.CountSql = CountSql
        cstmPersonsProgress.Params = Params
        cstmPersonsProgress.ShowButton = True

    End Sub
End Class
